package com.zhf.mapper;

import com.zhf.domain.Orders;
import com.zhf.domain.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @Author: ZhaoHuanfeng
 * @Date: 2020/11/14 16:12
 */
public interface OrderMapper {

    /**
     * 查询所有订单及对应用户信息
     * @return
     */
    @Select("select * from orders")
    @Results({//代替的就是ResultMap标签 id标签 result标签
            @Result(property = "id" ,column = "id" ,id = true),
            @Result(property = "ordertime" ,column = "ordertime"),
            @Result(property = "total" ,column = "total"),
            @Result(property = "uid" ,column = "uid"),
            @Result(property = "user",javaType = User.class ,column = "uid" ,one = @One(select = "com.zhf.mapper.UserMapper.findById" ,fetchType = FetchType.EAGER))
    })
    public List<Orders> findAllWithUser();

    /**
     * 查询用户的订单
     */
    @Select("select * from orders where uid=#{uid}")
    public List<Orders> findOrdersByUid(int uid);
}
